// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'lib-flexible'
import Vant from 'vant';
import 'vant/lib/index.css';
import VueClipboard from 'vue-clipboard2'
// import VConsole from 'vconsole'
// var vConsole = new VConsole();
import { Toast } from 'vant';

Vue.use(VueClipboard)
Vue.use(Vant);
Vue.config.productionTip = false
router.beforeEach((to, from, next) => {
  let _token = localStorage.getItem('shopwx');
  let openid = localStorage.getItem("openId")
  if (openid) {
    if (!_token) {
      if (to.path === '/login' || to.path === '/register' || to.path === '/wpass'|| to.path === '/xiyi') {
        next()
      } else {
        next('/login')
      }
    } else {
      if (to.path == '/mysend') {
        console.log(localStorage.getItem('userInfo'))
        let user = JSON.parse(localStorage.getItem('userInfo')).account_type
        console.log(user)
        if (user == 1) {
          Toast.fail('暂无权限');
        } else {
          next()
        }
      } else {
        next();
      }
    }
  } else {
    if (to.path == '/auth') {
      next()
    } else {
      next('/auth')
    }
  }
  // if (!_token) {
  //   if (to.path === '/login' || to.path === '/register' || to.path === '/wpass') {
  //     next()
  //   } else {
  //     next('/login')
  //   }
  // } else {
  //   if (to.path == '/mysend') {
  //     console.log(localStorage.getItem('userInfo'))
  //     let user = JSON.parse(localStorage.getItem('userInfo')).account_type
  //     console.log(user)
  //     if (user == 1) {
  //       Toast.fail('暂无权限');
  //     } else {
  //       next()
  //     }
  //   } else {
  //     next();
  //   }
  // }

});
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

